#include "recboxitem.h"
#include "ui_recboxitem.h"
#include <QPropertyAnimation>
#include <QDebug>
recboxitem::recboxitem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::recboxitem)
{
    ui->setupUi(this);
    ui->musicImageBox->installEventFilter(this);
}

bool recboxitem::eventFilter(QObject *watched, QEvent *event)
{
    if(watched==ui->musicImageBox)
    {
        int height= ui->musicImageBox->height();
        int width = ui->musicImageBox->width();
        //拦截鼠标进入事件
        if(event->type()==QEvent::Enter)
        {
            QPropertyAnimation* as=new QPropertyAnimation(ui->musicImageBox,"geometry");
            as->setDuration(150);
            as->setStartValue(QRect(9,9,width,height));
            as->setEndValue(QRect(9,0,width,height));
            as->start();
            connect(as,&QPropertyAnimation::finished,this,[=](){
                delete as;
            });
            return true;
        }
        else if(event->type()==QEvent::Leave)
        {
            QPropertyAnimation* as=new QPropertyAnimation(ui->musicImageBox,"geometry");
            as->setDuration(150);
            as->setStartValue(QRect(9,0,width,height));
            as->setEndValue(QRect(9,9,width,height));
            as->start();
            connect(as,&QPropertyAnimation::finished,this,[=](){
                delete as;
            });
            return true;
        }
    }
    else
        return QObject::eventFilter(watched,event);
}

void recboxitem::setText(const QString& text)
{
    ui->rectext->setText(text);
}

void recboxitem::setImage(const QString& image)
{
    QString style="background-image:url("+image+");";
    ui->recMusicImage->setStyleSheet(style);
}



recboxitem::~recboxitem()
{
    delete ui;
}
